package com.share.common.utils;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class Base64Util {
    final static Base64.Encoder ENCODER = Base64.getEncoder();
    final static Base64.Decoder DECODER = Base64.getDecoder();

    public static String encode(byte[] bytes) {
        return ENCODER.encodeToString(bytes);
    }

    public static byte[] encode(String hexStr) {
        return ENCODER.encode(hexStr.getBytes(StandardCharsets.UTF_8));
    }

    public static String encodeToString(byte[] bytes) {
        return ENCODER.encodeToString(bytes);
    }

    public static byte[] decode(String hexStr) {
        return DECODER.decode(hexStr);
    }

    public static byte[] decode(byte[] bytes) {
        return DECODER.decode(bytes);
    }

    public static String decodeToString(String hexStr) {
        byte[] bytes = hexStr.getBytes(StandardCharsets.UTF_8);
        byte[] decode = decode(bytes);
        return new String(decode, StandardCharsets.UTF_8);
    }
}

